<!DOCTYPE html>
<html lang="ch">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>事件</title>
  </head>
  <body>
    <input
      type="button"
      id="btn1"
      value="事件绑定1"
      onclick="on()"
    /><br /><br />
    <input type="button" id="btn2" value="事件绑定2" onclick="on()" />

    <script>
      function on1() {
        document.getElementById("btn2").onclick = function () {
          alert("按钮2被点击了");
        };
      }

      function on() {
        alert("按钮被点击了");
      }
    </script>
  </body>
</html>
